<?php

namespace Common\Controller;
use Think\Controller;
/**
 * 类说明
 *
 * @author chengwei wang
 */
class AccessController extends Controller{
    
    private $m;  //验证的方法字符串
    private $c;
    private $f;
    public $role=array();

    public function __construct($m,$c,$f) {
        $this->m=$m;
        $this->c=$c;
        $this->f=$f;
        $this->getTable();
    }
    
    
    /*
     * 读取用户数据权限
     */
    private function getTable(){
        $sql="select a.tables ,a.pk,(case when b.fields is null then a.fd else b.fields end) as fields,a.fields as fds,b.datatypes,b.dataid
from mt_data_ac as a
left join (select * from mt_data_client_ac  where cid =".$_SESSION['userInfo']['cid'].") as b on a.id=b.dnid
where controller='".$this->m.'-'.$this->c."'";
        
        $data=M()->query($sql);
        if(!empty($data)){
            $return['tables']= substr($data[0]['tables'], 0,strlen(C('DB_PREFIX'))) ===C('DB_PREFIX') ? substr($data[0]['tables'],strlen(C('DB_PREFIX'))) : $data[0]['tables'];
            $return['fields']= unserialize(urldecode($data[0]['fields']));
            $return['dataid']= unserialize(urldecode($data[0]['dataid']));
            $return['fds']= unserialize(urldecode($data[0]['fds']));
            $return['datatypes']=$data[0]['datatypes'];
            $return['pk']=$data[0]['pk'];
            $this->role=$return;
        }else{
            $this->error('配置错误！请检查！');
            exit();
        }
    }
    

    


}
